package org.fastsyncer.core.service;

import java.io.File;
import java.util.List;

import org.fastsyncer.common.entity.MappingTask;
import org.fastsyncer.common.entity.Page;
import org.json.JSONObject;

public interface ManagerService {

    /**
     * 新增驱动
     * @Title: add 
     * @param mapping
     * @throws Exception
     * @return: String 驱动ID
     */
    String add(String mapping) throws Exception;

    /**
     * 修改驱动
     * 
     * @param mapping
     * @throws Exception
     */
    String update(String mapping) throws Exception;

    /**
     * 恢复驱动
     * 
     * @param id
     * @throws Exception
     */
    String enable(String id) throws Exception;

    /**
     * 禁用驱动
     * 
     * @param name
     * @throws Exception
     */
    String disable(String id) throws Exception;

    /**
     * 启动驱动
     * 
     * @param id
     * @throws Exception
     */
    String start(String id) throws Exception;

    /**
     * 停止驱动
     * 
     * @param id
     * @throws Exception
     */
    String stop(String id) throws Exception;

    /**
     * 删除驱动
     * 
     * @param id
     * @throws Exception
     */
    String delete(String id) throws Exception;

    /**
     * 获取驱动
     * @param id
     * @return
     * @throws Exception
     */
    MappingTask getDriver(String id) throws Exception;

    /**
     * 获取所有驱动
     * @return
     * @throws Exception
     */
    List<MappingTask> getDriverAll() throws Exception;
    
    /**
     * 分页获取驱动
     * @param list 过滤的驱动集合
     * @param driverName 驱动名称
     * @param pageIndex 页数
     * @param pageSize 页大小
     * @return
     * @throws Exception
     */
    Page getDriver(List<MappingTask> list, String driverName, int pageIndex, int pageSize) throws Exception;

    /**
     * 获取驱动同步日志
     * 
     * @param id
     * @throws Exception
     */
    List<String> getDriverLog(String id);
    
    /**
     * 获取驱动同步日志文件
     * 
     * @param id
     * @throws Exception
     */
    File getDriverLogFile(String id);

    /**
     * 同步数据
     * @Title: sync 
     * @param json 同步的內容,包括对应的驱动名,增刪改操作事件.
     * @throws Exception
     * @return: void
     */
    void sync(String json) throws Exception;

    /**
     * 同步所有失败的日志
     * @Title: syncDriverLogAll 
     * @param driverId 驱动ID
     * @throws Exception
     * @return: void
     */
    void syncDriverLogAll(String driverId) throws Exception;
    
    /**
     * 同步失败的日志
     * @Title: syncDriverLog 
     * @param msg 日志格式：
     * <pre>
     * {
     *  "id":"e2dd5c03e512495a9a9e7e958bdd9464",
     *  "rows":[
     *      {
     *          "i":0,
     *          "id":e2dd5c03e512495a9a9e7e958bdd9464_7cde28d343bc4dd58f1a6ea9f280d1c9
     *          "params":{xxx}
     *      },
     *      {xxx}, ...
     *  ]
     * }
     * </pre>
     * @throws Exception
     * @return: void
     */
    void syncDriverLog(JSONObject msg) throws Exception;
    
    /**
     * 删除失败的日志
     * @Title: delDriverLog 
     * @param msg 日志格式：
     * <pre>
     * {
     *  "id":"e2dd5c03e512495a9a9e7e958bdd9464",
     *  "del": [
     *      {
     *          "i":0,
     *          "id":e2dd5c03e512495a9a9e7e958bdd9464_7cde28d343bc4dd58f1a6ea9f280d1c9
     *      },
     *      {xxx}, ...
     *  ]
     * }
     * </pre>
     * @throws Exception
     * @return: void
     */
    void delDriverLog(JSONObject msg) throws Exception;
    
    /**
     * 新增日志
     * @Title: addDriverLog 
     * @param msg 日志格式：
     * <pre>
     * {
     *  "id":"e2dd5c03e512495a9a9e7e958bdd9464",
     *  "reason":[
     *      {"params":{xxx},"message":"xxx"}
     *  ]
     * }
     * </pre>
     * @throws Exception
     * @return: void
     */
    void addDriverLog(JSONObject msg) throws Exception;
    
}
